package ysc.cqnu.operdb.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ysc.cqnu.operdb.entity.ResultData;
import ysc.cqnu.operdb.entity.ResultUserInfo;
import ysc.cqnu.operdb.entity.User;
import ysc.cqnu.operdb.mapper.UserMapper;
import ysc.cqnu.operdb.service.UpdateUserInfoNoImgService;

import java.io.FileOutputStream;

@Service
public class UpdateUserInfoNoImgServiceImpl implements UpdateUserInfoNoImgService {
    @Autowired
    private ResultData resultData;
    @Autowired
    private ResultUserInfo resultLogin;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private User user;
    @Override
    public ResultData updateUserInfoNoImgService(String name, String age, String sex, String emile) {
        try {
            user = userMapper.findByName(name);
            resultData.flag="ImgSuccess";
            resultLogin.age=age;
            resultLogin.sex=sex;
            resultLogin.emile=emile;
            resultLogin.userImgSrc=user.getUserImgSrc();
            //写入数据库
            userMapper.updateUserInfo(name,age,sex,emile);
            resultData.data=resultLogin;
        } catch (Exception e) {
            resultData.flag="ImgFail";
            resultData.data=null;
            return resultData;
        }
        return resultData;
    }
}
